package cn.com.huzo.service.tech.impl;

import cn.com.huzo.model.entities.tech.PieceYardageLinesProductSizeEntity;
import cn.com.huzo.repository.tech.PieceYardageLinesProductSizeRepository;
import cn.com.huzo.repository.tech.PieceYardageLinesRepository;
import cn.com.huzo.service.tech.PieceYardageLinesProductSizeManager;
import huzofw.service.impl.GenericManagerImpl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 单耗-成品尺码管理服务对象类实现。
 *
 * @author 吴旭
 */
@Service("PieceYardageLinesProductSizeManager")
public class PieceYardageLinesProductSizeManagerImpl extends GenericManagerImpl<PieceYardageLinesProductSizeEntity, String>
        implements PieceYardageLinesProductSizeManager {

    @Resource(name = "PieceYardageLinesRepository")
    private PieceYardageLinesRepository _dao_lines;

    @Resource(name = "PieceYardageLinesProductSizeRepository")
    private PieceYardageLinesProductSizeRepository _dao_lines_product_size;

    /**
     * {@inheritDoc}
     *
     * @throws java.lang.Exception
     */
    @Override
    public List<PieceYardageLinesProductSizeEntity> fetchByHeaderId(Long headerId) throws Exception {
        return _dao_lines_product_size.fetchByHeaderId(headerId);
    }

    /**
     * {@inheritDoc}
     *
     */
    @Override
    @Transactional
    public Map<String, Object> insert(List<PieceYardageLinesProductSizeEntity> itemList) throws Exception {
        Map<String, Object> _result = new HashMap();
        // 插入新增的成品尺码
        _dao_lines_product_size.insert(itemList);

        _result.put("Success", true);
        _result.put("LinesList", _dao_lines.fetchByHeaderKey(itemList.get(0).getHeaderId()));
        _result.put("ProductSizeNode", _dao_lines_product_size.fetchByHeaderId(itemList.get(0).getHeaderId()));

        return _result;
    }

    /**
     * {@inheritDoc}
     *
     * @throws java.lang.Exception
     */
    @Override
    @Transactional
    public Map<String, Object> update(List<PieceYardageLinesProductSizeEntity> itemList) throws Exception {
        Map<String, Object> _result = new HashMap();

        Integer rowsAffected = _dao_lines_product_size.update(itemList);
        if (rowsAffected > 0) {
            _result.put("Success", true);
            _result.put("LinesList", _dao_lines.fetchByHeaderKey(itemList.get(0).getHeaderId()));
            _result.put("ProductSizeNode", _dao_lines_product_size.fetchByHeaderId(itemList.get(0).getHeaderId()));
        } else {
            _result.put("Success", false);
        }

        return _result;
    }

    /**
     * {@inheritDoc}
     *
     * @throws java.lang.Exception
     */
    @Override
    @Transactional
    public Map<String, Object> deleteLines(PieceYardageLinesProductSizeEntity instance) throws Exception {
        Map<String, Object> _result = new HashMap();

        Integer rowsAffected = _dao_lines_product_size.delete(instance.getLinesId());
        if (rowsAffected > 0) {
            _result.put("LinesList", _dao_lines.fetchByHeaderKey(instance.getHeaderId()));
            _result.put("ProductSizeNode", _dao_lines_product_size.fetchByHeaderId(instance.getHeaderId()));
            _result.put("Success", true);
        } else {
            _result.put("Success", false);
        }

        return _result;
    }
}
